package org.app4j.passport.service;

import java.util.regex.Pattern;


/**
 * @author Chi
 */
public class Role {
  public final String ROLE_SELF = "self";
  public final String ROLE_ADMIN = "admin";

  public final String ROLE_SERIAL_PREFIX = "lv";
  public final String ROLE_SERIAL_PATTERN = "lv\\d+";


  public String getNextSerialRole(String role) {
    if (isSerialRole(role)) {
      int level = Integer.valueOf(role.substring(ROLE_SERIAL_PREFIX.length()));
      return ROLE_SERIAL_PREFIX + (level + 1);
    }
    return null;
  }

  public boolean isSerialRole(String role) {
    Pattern p = Pattern.compile(ROLE_SERIAL_PATTERN);
    return p.matcher(role).matches();
  }



}
